<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-form :inline="true" :model="searchForm" label-width="80px" class="demo-form-inline">
      <el-form-item label="账套编码">
        <el-input v-model="searchForm.contractId" size="small" placeholder="请输入账套编码" />
      </el-form-item>
      <el-form-item label="公司名称">
        <el-input v-model="searchForm.companyName" size="small" placeholder="请输入部门名称" />
      </el-form-item>
      <el-form-item label="门店名称">
        <el-input v-model="searchForm.storeName" size="small" placeholder="请输入部门名称" />
      </el-form-item>
      <el-form-item label="合同编号">
        <el-input v-model="searchForm.storeId" size="small" placeholder="请输入部门名称" />
      </el-form-item>
      <el-form-item label="支付状态">
        <el-select v-model="searchForm.payType" size="small" placeholder="请选择支付状态">
          <el-option label="全部" value="0" />
          <el-option label="未支付" value="1" />
          <el-option label="已支付" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" icon="el-icon-search" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 按钮组 -->
    <el-row>
      <el-button type="primary" size="small" @click="isPaymentPopUp">付款</el-button>
      <el-button type="primary" size="small">查看凭证</el-button>
      <el-button type="primary" size="small">导出租金支付数据</el-button>
      <el-button type="primary" size="small">撤销付款</el-button>
    </el-row>

    <!-- 数据 -->
    <!-- 表格 -->
    <el-table v-loading="loading" :data="formData">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="合同编号" prop="contractId" :show-overflow-tooltip="true" />
      <el-table-column label="支付状态" prop="deptName" :show-overflow-tooltip="true" />
      <el-table-column label="公司名称" prop="companyName" :show-overflow-tooltip="true" />
      <el-table-column label="套账编码" prop="financialCode" :show-overflow-tooltip="true" />
      <el-table-column label="门店编码" prop="storeId" :show-overflow-tooltip="true" />
      <el-table-column label="门店名称" prop="storeName" :show-overflow-tooltip="true" />
      <el-table-column label="期次" prop="Qs" :show-overflow-tooltip="true" />
      <el-table-column label="本期开始日期" prop="contractStartTime" :show-overflow-tooltip="true" />
      <el-table-column label="本期结束日期" prop="contractEndTime" :show-overflow-tooltip="true" />
      <el-table-column label="计划付款日期" prop="email" :show-overflow-tooltip="true" />
      <el-table-column label="本期计划付款金额" prop="email" :show-overflow-tooltip="true" />
      <el-table-column label="本期剩余待支付金额" prop="email" :show-overflow-tooltip="true" />
      <el-table-column label="本期实际付款金额" prop="contractMoneyNum" :show-overflow-tooltip="true" />
      <el-table-column label="本期减免金额" prop="jm" :show-overflow-tooltip="true" />
      <el-table-column label="提交时间" prop="endTime" :show-overflow-tooltip="true" />
      <el-table-column label="提交人" prop="operUser" :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEdit(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--批量收款-->
    <el-dialog title="批量付款" width="80%" :visible.sync="isPayment" :before-close="closePopUp">
      <!--收款-->
      <div class="batchPayment">
        <h2 class="title">收款</h2>
        <el-table
          :data="payment"
          border
          style="width: 100%">
          <el-table-column
            prop="pId"
            label="序号"
            width="80">
          </el-table-column>
          <el-table-column
            prop="companyName"
            label="公司名称"
            width="180">
          </el-table-column>
          <el-table-column
            prop="storeId"
            label="门店编码"
            width="180">
          </el-table-column>
          <el-table-column
            prop="storeName"
            label="门店名称"
            width="180">
          </el-table-column>
          <el-table-column
            prop="actualPaymentTime"
            label="实际付款日期"
            width="230">
            <template slot-scope="scope">
              <el-date-picker
                v-model="scope.row.actualPaymentTime"
                type="date"
                placeholder="选择日期">
              </el-date-picker>
            </template>
          </el-table-column>
          <el-table-column
            prop="actualPaymentMoney"
            label="实际付款金额"
            width="180">
            <template slot-scope="scope">
              <el-input v-model="scope.row.actualPaymentMoney" ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="currentStartTime"
            label="本期开始日期"
            width="230">
          </el-table-column>
          <el-table-column
            prop="currentEndTime"
            label="本期结束日期"
            width="230">
          </el-table-column>
          <el-table-column
            prop="planPaymentTime"
            label="本期计划付款日期"
            width="230">
          </el-table-column>
          <el-table-column
            prop="planPaymentMoney"
            label="本期计划付款金额">
          </el-table-column>
          <el-table-column
            prop="contractId"
            label="合同编号"
            width="230">
          </el-table-column>
          <el-table-column
            label="操作"
            width="100">
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="deleteRow(scope)"
                type="text"
                size="small">
                移除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--收款流水-->
      <div class="paymentWater">
        <h2 class="title">我司收款流水</h2>
        <el-button type="primary" @click="runWater">新增</el-button>
        <div class="sameAccount">
          <el-checkbox v-model="checked" @change="isChecked">使用同一付款银行账号（我司）</el-checkbox>
          <span class="accountWater">
              付款银行账号:<el-input placeholder="请输入内容" v-model="iSbackAccount"></el-input>
            </span>
        </div>
        <el-table
          border
          style="width: 100%"
          :data="collectionInfoForm"
          class="insetRow">
          <el-table-column
            prop="companyBankAccount"
            label="付款银行账号（我司）"
            width="230">
            <template slot-scope="scope">
              <el-input v-model="scope.row.companyBankAccount" ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="companyBankName"
            label="付款银行名称"
            width="180" >
          </el-table-column>
          <el-table-column
            prop="paymentName"
            label="收款人"
            width="180">
            <template slot-scope="scope">
              <el-input v-model="scope.row.paymentName" ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="landadyBankAccout"
            label="收款银行账号（房东）"
            width="230">
            <template slot-scope="scope">
              <el-input v-model="scope.row.landadyBankAccout" ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="landadyBankDeposit"
            label="收款开户行"
            width="230">
            <template slot-scope="scope">
              <el-input v-model="scope.row.landadyBankDeposit" ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="payTel"
            label="联系电话"
            width="180">
            <template slot-scope="scope">
              <el-input v-model="scope.row.payTel" ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="payMoney"
            label="收款金额"
            width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.payMoney" ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            width="100">
            <el-button type="primary">删除</el-button>
          </el-table-column>
        </el-table>
        <span class="totalPrice">收款总计:{{totalPriceNum}}</span>
      </div>
      <!--按钮组-->
      <div class="paymentBtn">
        <el-button type="primary" @click="subpayee">提交</el-button>
        <el-button type="primary" @click="closePopUp">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getPayout, paymentMoney, queryRentColletion} from '@/api/rent'
export default {
  name: 'VueAdminTemplatePayout',
  data() {
    return {
      searchForm: {
        contractId: '',
        companyName: '',
        storeName: '',
        payType: '2'
      },
      // 表格加载
      loading: true,
      formData: [],
      // 批量收款数据
      payment: [],
      // 显示批量付款
      isPayment: false,
      // 同一收款账号
      iSbackAccount: '',
      // 是否使用同一账号收款
      checked: false,
      // 总条数
      total: 0,
      // 每页显示
      limit: 5,
      // 当前页数
      page: 1,
      // 流水数据
      collectionInfoForm: [],
      // 总计金额
      totalPriceNum: 0,
      // 查看凭证弹窗
      isCheck: false,
      // 凭证数据
      checkForm: [],
      // 导出组件收款数据弹窗
      isDetails: false
    }
  },
  created() {
    this.getPayoutData()
  },
  methods: {
    getPayoutData() {
      getPayout(this.searchForm).then(res => {
        const { data } = res
        data.data.date.forEach(item => {
          item.Qs = Math.ceil(Math.random() * 5)
          item.jm = 0
        })
        this.formData = data.data.date
        console.log(data.date)
        this.loading = false
      })
    },
    // 关闭dialog
    closePopUp() {
      this.ispreview = false
      this.isPayment = false
      this.isCheck = false
      this.isDetails = false
    },
    // 搜索按钮
    onSubmit() {
      this.getPayoutData()
    },
    isPaymentPopUp() {
      this.isPayment = true
    },
    // 是否使用同一付款银行
    isChecked(val) {
      if (val) {
        this.iSbackAccount = this.collectionInfoForm[0].companyBankAccount
      } else {
        this.iSbackAccount = ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>

.el-table{
	margin-top: 20px;
}
.title{
  border-left: 6px solid #409EFF;
  text-align: left;
  height: 50px;
  line-height: 50px;
  padding-left: 10px;
}
.paymentWater{
  margin-top: 30px;
}
.el-pagination{
  margin-top: 20px;
  margin-left: 70%;
}
.sameAccount{
  display: flex;
  height: 60px;
  line-height: 60px;
}
.accountWater{
  display: flex;
  margin-left: 20px;
  width: 400px;
}
.accountWater>.el-input{
  width:70% !important;
  margin-left: 10px;
}
.totalPrice {
  display: inline-block;
  margin-top: 20px;
}
.paymentBtn {
  margin-top: 20px;
}
</style>
